define(["jquery", "cookie"], function($){

    function Header() {
        this.load();
    }

    Header.prototype = {
        constructor: Header,
        // 加载头部与尾部
        load: function() {
            $.get("/html/include/header.html", $.proxy(this.headerHandler, this));
            $("footer").load("/html/include/footer.html");
        },
        headerHandler: function(data) {
            $("header").html(data);
            this.loadLoginUser();
        },
        loadLoginUser: function() {
            $.cookie.json = true;
            var user = $.cookie("login-user");
            if (user)
                $(".top").empty().html(`<a href="#">${user}</a> <a href="#" class="logout">注销</a>`);
            $(".logout").on("click",$.proxy(this.shanchu, this))
        },
        shanchu(){
            $.cookie.json = true;
            let login= $.cookie("login-user");
            $.cookie("login-user",login,{expires:-1,path:"/"});
             $(".top").empty().html(`<ul>
                        <li>
                        <a href="/html/login.html" class="link-login">登录</a>
                        <span><img src="/img/xian.jpg"/></span>
                        <a href="/html/register.html">注册</a>
                        </li>
                    </ul>`);

        }
    }
    new Header();
});